package com.lagou.homework.sort;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class SortDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "SortDrive");
        //驱动
        job.setJarByClass(SortDriver.class);
        //mapper   reducer
        job.setMapperClass(SortMapper.class);
        job.setReducerClass(SortReducer.class);
        //mappper输出类型
        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(NullWritable.class);
        //最终输出类型
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);
        //输入输出路径
        FileInputFormat.setInputPaths(job,new Path("C:\\Users\\Administrator\\Desktop\\作业资料" ));
        FileOutputFormat.setOutputPath(job,new Path("C:\\Users\\Administrator\\Desktop\\作业资料\\output"));
        //提交任务
        boolean flag = job.waitForCompletion(true);

        System.exit(flag?0:1);
    }
}
